package zzzxb;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author Zzzxb  2019/8/10 20:55
 * @description:
 */
public class Demo {
    @Test
    public void givenTwoDatesBeforeJava8_whenDifferentiating_thenWeGetSix()
            throws ParseException {

        //
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
        Date firstDate = sdf.parse("2017/10/1");
        Date secondDate = sdf.parse("2017/10/5");

        long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
        long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);

        System.out.println(diff);
//        assertEquals(diff, 6);
    }

}
